import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop|Qt.AlignmentFlag.AlignLeft)
        btn = QPushButton('Default Push Button')        
        btn.clicked.connect(self.OnButtonClicked)
        layout.addWidget(btn)

        btn = QPushButton('Disabled Push Button')        
        btn.setEnabled(False)
        layout.addWidget(btn)

        btn = QPushButton(QIcon(f'{self.parent.getAppDir()}/resources/confirm.png'),'Icon Button')
        btn.clicked.connect(self.OnIconButtonClicked)
        layout.addWidget(btn)

        btn = QPushButton('Checkable Button',self,checkable=True)        
        btn.clicked.connect(self.OnCheckButtonClicked)
        layout.addWidget(btn)

        btn = QPushButton('Auto Repeat Button',self,autoRepeat=True)        
        btn.clicked.connect(self.OnAutoRepeatButtonClicked)
        layout.addWidget(btn)

        btn = QPushButton('Auto Repeat Delay Button',self,autoRepeat=True,autoRepeatDelay=2000)        
        btn.clicked.connect(self.OnAutoRepeatDelayButtonClicked)
        layout.addWidget(btn)

        btn = QPushButton('Auto Repeat Interval Button',self,autoRepeat=True,autoRepeatInterval=1000)        
        btn.clicked.connect(self.OnAutoRepeatIntervalButtonClicked)
        layout.addWidget(btn)

        group = QGroupBox('Auto Exclusive Button')
        groupLayout = QVBoxLayout()

        btn = QPushButton('Button1',self,objectName='Button1',autoExclusive=True,checkable=True)        
        btn.clicked.connect(self.OnAutoButtonClicked)
        groupLayout.addWidget(btn)

        btn = QPushButton('Button2',self,objectName='Button2',autoExclusive=True,checkable=True)        
        btn.clicked.connect(self.OnAutoButtonClicked)
        groupLayout.addWidget(btn)

        btn = QPushButton('Button3',self,objectName='Button3',autoExclusive=True,checkable=True)        
        btn.clicked.connect(self.OnAutoButtonClicked)
        groupLayout.addWidget(btn)
        group.setLayout(groupLayout)
        layout.addWidget(group)

        self.setLayout(layout)

    def OnButtonClicked(self,event):            
        self.parent.OnShowMessage('Default Button Clicked')
    
    def OnIconButtonClicked(self,event):            
        self.parent.OnShowMessage('Icon Button Clicked')

    def OnCheckButtonClicked(self,event):
        self.parent.OnShowMessage(f'Checkable Button Clicked,isChecked:{event}')

    def OnAutoRepeatButtonClicked(self,event):
        self.parent.OnShowMessage(f'Auto Repeat Button Clicked')

    def OnAutoRepeatDelayButtonClicked(self,event):
        self.parent.OnShowMessage(f'Auto Repeat Delay Button Clicked')

    def OnAutoRepeatIntervalButtonClicked(self,event):
        self.parent.OnShowMessage(f'Auto Repeat Interval Button Clicked')

    def OnAutoButtonClicked(self,event):
        objectName = self.sender().objectName()
        self.parent.OnShowMessage(f'{objectName} Clicked,isChecked:{event}')
        

def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet